﻿<?php
/**
 * Created by JetBrains PhpStorm.
 * User: James
 * Date: 12-6-6
 * Time: 下午10:42
 * To change this template use File | Settings | File Templates.
 */
class Marks extends CI_Controller{
    public function __construct(){
        parent::__construct();
        $this->load->model("mark_model");
    }
    public function index(){
        $this->load->view('templates/header');
        $this->load->view('easymark/index');
        $this->load->view('templates/footer');
    }
    public function view(){
        $this->load->helper('form');

        $data['marks']=$this->mark_model->get_marks();

        $this->load->view('easymark/view', $data);
    }

    public function create()
    {
        $this->load->helper('form');
        $this->load->library('form_validation');


        $this->form_validation->set_rules('title', 'required');
        $this->form_validation->set_rules('address', 'required');

        if ($this->form_validation->run() === FALSE)
        {
           echo "0";
        }
        else
        {
            $save=$this->mark_model->insert_marks();
            if($save)
            {
                echo "1";
            }else
            {
                echo "0";
            }

        }
    }

    public function delete()
    {
        $this->load->helper('form');
        $this->load->library('form_validation');


        $this->form_validation->set_rules('id', 'required');

        if ($this->form_validation->run() === FALSE)
        {
            echo "0";
        }
        else
        {
            $del=$this->mark_model->del_marks();
            if($del)
            {
                echo "1";
            }else
            {
                echo "0";
            }

        }
    }

    public function update()
    {
        $this->load->helper('form');
        $this->load->library('form_validation');


        $this->form_validation->set_rules('id', 'required');
        $this->form_validation->set_rules('title', 'required');
        $this->form_validation->set_rules('address', 'required');


        if ($this->form_validation->run() === FALSE)
        {
            echo "0";
        }
        else
        {
            $del['marks']=$this->mark_model->update_marks();

            if($del)
            {
                $this->load->view('easymark/view', $del);
            }
            else
            {
                echo "0";
            }

        }
    }

}